<?php

namespace app\admin\controller;

use app\admin\model\QjConfigModel;


class Config extends Base {

    public function addConfig()
    {
        $name = input('name', '');
        $en_name = input('en_name', '');
        $for_the_record = input('for_the_record', '');
        $bg_img = input('bg_img', '');

        if (empty($name) || empty($en_name)) {
            $res['success'] = false;
            $res['desc'] = '网站名称不能为空';
            $res['errorcode'] = '200022';
            return json($res);
        }

        if (empty($for_the_record)) {
            $res['success'] = false;
            $res['desc'] = '网站备案号不能为空';
            $res['errorcode'] = '200022';
            return json($res);
        }

        $data = [
            'name' =>$name,
            'en_name' =>$en_name,
            'for_the_record' =>$for_the_record,
            'bg_img' =>$bg_img,
        ];

        $model = new QjConfigModel();
        $res = $model->addConfig($data);
        return json($res);
    }


    public function getConfigInfo()
    {

        $model = new QjConfigModel();
        $res = $model->getConfigInfo();
        return json($res);

    }
    

    public function delConfig()
    {
        $config_id = input('config_id', 0);
        if (empty($config_id)) {
            $res['success'] = false;
            $res['desc'] = '参数错误';
            $res['errorcode'] = '200022';
            return json($res);
        }
        $regionModel = new QjConfigModel();
        $res = $regionModel->delConfigInfo($config_id);
        return json($res);

    }

    public function upConfig()
    {
        $name = input('name', '');
        $config_id = input('config_id', 0);
        $en_name = input('en_name', '');
        $for_the_record = input('for_the_record', '');
        $bg_img = input('bg_img', '');
        $update = [];
        if (empty($config_id)) {
            $res['success'] = false;
            $res['desc'] = '网站名称不能为空';
            $res['errorcode'] = '200022';
            return json($res);
        }
        if (!empty($name) && !empty($en_name)) {
            $update['name'] = $name;
            $update['en_name'] = $en_name;
        }

        if (!empty($for_the_record)) {
            $update['for_the_record'] = $for_the_record;
        }

        if (!empty($bg_img)) {
            $update['bg_img'] = $bg_img;
        }
        $model = new QjConfigModel();
        $res = $model->upConfigInfo($config_id, $update);
        return json($res);
    }

}